package bs

import scala.xml.NodeSeq
import net.liftweb.http.Templates

import net.liftweb._
import http._
import util._
import Helpers._
import java.nio.file.DirectoryIteratorException

case class NavTab(pairs: (String, NodeSeq)*) extends LiftComponent with Activable{
  override val template: NodeSeq = Templates("templates-hidden" :: "bs" :: "_navtab" :: Nil).get


  override def transformer = {
    import code.lib.ExtCssSel._

    val tabId = s"navtab-${(math.random * 10).toInt}"
    def contentId(index: Int) = s"$tabId-content-$index"

    ".nav [id]" #> tabId &
      "li" #> pairs.zipWithIndex.map { case ((text, content), index) =>
        "a [href]" #> s"#${contentId(index)}" &
          "a *" #> text &? (_active == index) -> "li [class+]" #> "active"
      } &
      ".tab-pane" #> pairs.zipWithIndex.map { case ((text, content), index) =>
        ".tab-pane [id]" #> contentId(index) &
          ".tab-pane *" #> content &? (_active == index) -> ".tab-pane [class+]" #> "active"
      } &
      ".container ^*" #> "*"
  }



}
